import 'package:flutter/material.dart';
import 'package:play_android/com/zhihaoliang/const/AppStr.dart';
import 'package:play_android/com/zhihaoliang/play/hotpage/view/HotPage.dart';

import 'SearchListPage.dart';

/// **************************************************************************
/// 搜索页面
/// **************************************************************************

class SearchPage extends StatefulWidget {
  String searchKey;

  SearchPage([this.searchKey]);

  @override
  State<StatefulWidget> createState() {
    return _SearchPageState();
  }
}

class _SearchPageState extends State<SearchPage> {
  TextEditingController _searchConter = TextEditingController();

  SearchListPage _searchListPage;

  @override
  void initState() {
    super.initState();
    _searchConter.text = widget.searchKey;
    changContent();
  }

  void changContent() {
    _searchListPage = SearchListPage(_searchConter.text);
  }

  @override
  Widget build(BuildContext context) {
    TextField serachFile = TextField(
      autofocus: true,
      textInputAction: TextInputAction.search,
      onSubmitted: (String) {
        changContent();
      },
      style: TextStyle(color: Colors.white),
      decoration: InputDecoration(
        border: InputBorder.none,
        hintText: AppStr.KEY_HIDE_SEARCH,
        hintStyle: TextStyle(color: Colors.white),
      ),
      controller: _searchConter,
    );

    return Scaffold(
        appBar: AppBar(
          title: serachFile,
          actions: <Widget>[
            IconButton(
              icon: Icon(Icons.search),
              onPressed: () {
                setState(() {
                  changContent();
                });
              },
            ),
            IconButton(
              icon: Icon(Icons.close),
              onPressed: () {
                setState(() {
                  _searchConter.clear();
                });
              },
            ),
          ],
        ),
        body: (_searchConter.text == null || _searchConter.text.isEmpty)
            ? Center(
                child: HotPage(),
              )
            : _searchListPage);
  }
}
